class_name CPubDataDefine

var m_UUID
var tblPubPlayerInfo: CPubPlayerInfo


static func GetType():
    return TableCommonDefine.EDataDefineType.eDDT_Pub


func _init(_uuid, _context):
    m_UUID = _uuid
    self.Reset()


func ClearData():
    # "client none"
    pass


func Reset():
    self.tblPubPlayerInfo = CPubPlayerInfo.new(self.m_UUID)


func GetUUID():
    return self.m_UUID



func GetDBDefine():
    return null


func GetDataDefineName():
    return "CPubDataDefine"



func UnPack(_bufferStream, _size, _pos):
    assert( _bufferStream.GetDataSize() == _size )
    _bufferStream.SetPosition( _pos )
    var nCount = 0
    var nUUID = 0

    self.tblPubPlayerInfo.UnPack(_bufferStream)


func GetTableByTableId(_nTblId):
    # var szObjName = 'tbl' .. AllTables[_nTblId]
    # if self[szObjName] == null :
    #     return null
    
    # return self[szObjName]
    return null


func SynFieldData(_nOperType,_tableID, _nDataUUID, _fieldID,  _dataStream, _nBufferSize, _nPos):

    var tbl = self.GetTableByTableId(_tableID)
    if null == tbl :
        return false
    
    if _nOperType == TableCommonDefine.eCTOp_Update:
        var buffStream = CBufferStream.new(null);
        buffStream.Load(_dataStream, _nPos, _nBufferSize)
        return tbl.UnPackField( _fieldID,buffStream, _nBufferSize)
    elif _nOperType == TableCommonDefine.eCTOp_Insert:
        var buffStream = CBufferStream.new(null)
        buffStream.Load(_dataStream, _nPos, _nBufferSize)
        tbl.AddField(_fieldID,buffStream)
        return true
    elif _nOperType == TableCommonDefine.eCTOp_Delete:
        tbl.DelField(_fieldID)
        return true
    elif _nOperType == TableCommonDefine.eCTOp_Assign:
        var buffStream = CBufferStream.new(null)
        buffStream.Load(_dataStream, _nPos, _nBufferSize)
        var nArraySize = buffStream.ReadUint32()
        tbl.SetCurNum(nArraySize)
    
    return false


func AddTableListener(_szTable, _szField, _szCallback, caller):
    var szFunGetTableName = "Get%s" % [ _szTable]
    if not has_method(szFunGetTableName):
        return false
    
    var table = call(szFunGetTableName)
    table.AddEventListener(_szField, _szCallback, caller)


func RemoveTableListener(_szTable, _szField, _szCallback, caller):
    var szFunGetTableName = "Get%s" % [ _szTable]
    if not has_method(szFunGetTableName):
        return false
    
    var table = call(szFunGetTableName)
    table.RemoveEventListener(_szField, _szCallback, caller)

func CopyFrom(_pOther):
    self.m_UUID = _pOther.m_UUID
    self.tblPubPlayerInfo.CopyFrom(_pOther.tblPubPlayerInfo)



func GetPubPlayerInfo():    
    return self.tblPubPlayerInfo


